package character;

import board.BoardUtil;
import board.PatternType;
import modifier.character.CharacterModifier;
import modifier.character.CharacterModifierActionSpeed;
import game.DataStore;
import game.GameUtil;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import misc.Vector3i;

public abstract class CharacterUtil {

    public static Collection<Vector3i> getOccupiedLocations(Vector3i boardLocation, CharacterSize characterSize) {
	Set<Vector3i> occupiedLocations = new HashSet<Vector3i>();
	occupiedLocations.add(boardLocation.clone());
	if(characterSize == CharacterSize.SINGLE) {
	    return occupiedLocations;
	} else if(characterSize == CharacterSize.DOUBLE) {
	    occupiedLocations.add(boardLocation.clone().addZ(1));
	} else if(characterSize == CharacterSize.FOUR) {
	    occupiedLocations.add(boardLocation.clone().addZ(1));
	    occupiedLocations.add(boardLocation.clone().addX(1));
	    occupiedLocations.add(boardLocation.clone().addZ(1).addX(1));
	}
	Iterator<Vector3i> iter = occupiedLocations.iterator();
        while (iter.hasNext()) {
            if(!DataStore.board.isTileAtLocation(iter.next())) {
                iter.remove();
            }
        }
	return occupiedLocations;
    }
    
    public static boolean checkCharacterInRange(MyCharacter character, MyCharacter target, PatternType rangeType, int rangeSize) {
        for(Vector3i occupiedLocation : character.getOccupiedLocations()) {
            if(GameUtil.containsAny(BoardUtil.getPatternLocations(rangeType, rangeSize, true, occupiedLocation), target.getOccupiedLocations())) {
                return true;
            }
        }
        return false;
    }
}
